(() => {
	let ele = {};
	ele.zadan = $("#zadan");
	ele.modal_egg = $("#modal-egg");
	ele.close_egg = $("#close-egg");
	ele.tips3 = $("#tips3");
	ele.modal_tips3 = $("#modal-tips3");
	ele.close_tips3 = $("#close-tips3");
	ele.yd_money = $("#yd_money");
	ele.jd_money = $("#jd_money");
	ele.cd_money = $("#cd_money");
	ele.zsd_money = $("#zsd_money");
	ele.yd_wenxin = $("#yd_wenxin");
	ele.ydc_num = $("#ydc_num");
	ele.cdc_num = $("#cdc_num");
	ele.yd_open = $("#yd_open");
	ele.jd_open = $("#jd_open");
	ele.cd_open = $("#cd_open");
	ele.zsd_open = $("#zsd_open");
	ele.yd_cuizhi_open = $("#yd_cuizhi_open");
	ele.cd_cuizhi_open = $("#cd_cuizhi_open");
	ele.yd_cuizhi_open2 = $("#yd_cuizhi_open2");
	ele.cd_cuizhi_open2 = $("#cd_cuizhi_open2");
	ele.modal_tips2 = $("#modal-tips2");
	ele.close_tips2 = $("#close-tips2");
	ele.recieveimg = $("#recieveimg");
	ele.tipsbtn = $("#tipsbtn");
	ele.recievenum = $("#recievenum");
	ele.xianwan = $("#xianwan");
	ele.xianwan_open = $("#xianwan_open");
	ele.modal_activity = $("#modal-activity");
	ele.close_activity = $("#close-activity");
	ele.zanwei = $(".zanwei");
	ele.mingzi = $("#mingzi");
	ele.recieveimg2 = $("#recieveimg2");
	ele.floimg = $("#floimg");
	ele.modal_explian = $("#modal-explian");
	ele.explian = $("#explian");
	ele.close_explian = $("#close-explian");

	let ydc = "";
	let cdc = "";

	let ptype = "";

	let uid = getCookie("userid");

	let aidfa = "";
	
	//关闭 说明
	ele.close_explian.onclick = () => {
		closeMdl(ele.modal_explian);
	};
	
	// 闲玩
	let ua = navigator.userAgent.toLowerCase();
	if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
		//判断iPhone|iPad|iPod|iOS
		ptype = 1;
	} else if (/(Android)/i.test(ua)) {
		//判断Android
		ptype = 2;
	} else {
		ptype = 3;
	}

	for (let i = 0; i < ele.zanwei.length; i++) {
		ele.zanwei[i].onclick = () => {
			openTips("敬请期待！");
		};
	}

	//开启 限时活动 试玩
	ele.xianwan.onclick = () => {
		openMdl(ele.modal_activity);
	};

	//关闭 限时活动 试玩
	ele.close_activity.onclick = () => {
		closeMdl(ele.modal_activity);
	};

	//开启 砸金蛋
	ele.zadan.onclick = () => {
		openMdl(ele.modal_egg);
	};

	//关闭 砸金蛋
	ele.close_egg.onclick = () => {
		closeMdl(ele.modal_egg);
	};

	//开启 砸金蛋说明
	ele.tips3.onclick = () => {
		openMdl(ele.modal_tips3);
	};

	//关闭 砸金蛋说明
	ele.close_tips3.onclick = () => {
		closeMdl(ele.modal_tips3);
	};

	//关闭 恭喜获得
	ele.close_tips2.onclick = () => {
		closeMdl(ele.modal_tips2);
	};
	ele.tipsbtn.onclick = () => {
		closeMdl(ele.modal_tips2);
	};

	goldEggIndex();
	// 砸蛋 列表
	function goldEggIndex() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.GOLD_EGG_INDEX,
			method: "GET",
			header: {
				Authorization: token,
			},
			success: (res) => {
				if (res.code == 1) {
					// console.log(res.data.yd.num == 0);
					ele.yd_money.innerHTML =
						res.data.yd.num == 0 ? res.data.yd.money : "免费";
					ele.jd_money.innerHTML = res.data.jd.money;
					ele.cd_money.innerHTML =
						res.data.cd.num == 0 ? res.data.cd.money : "免费";
					ele.zsd_money.innerHTML = res.data.zsd.money;
					ele.ydc_num.innerHTML = res.data.yd.num;
					ydc = res.data.yd.num;
					ele.cdc_num.innerHTML = res.data.cd.num;
					cdc = res.data.cd.num;
					ele.yd_wenxin.innerHTML =
						"*温馨提示：银蛋每日可砸蛋次数(" +
						res.data.yd.lose_num +
						"/" +
						res.data.yd.all_num +
						")";
				} else openTips(res.msg || "未知错误");
			},
		});
	}

	// 开启银蛋 银币
	ele.yd_open.onclick = () => {
		goldEggBangEgg(6);
	};

	// 开启银蛋 锤子
	ele.yd_cuizhi_open.onclick = () => {
		// if(ydc > 0) {
		goldEggBangEgg(6);
		// } esl
	};
	// 开启银蛋 锤子
	ele.yd_cuizhi_open2.onclick = () => {
		goldEggBangEgg(6);
	};

	// 开启金蛋 银币
	ele.jd_open.onclick = () => {
		goldEggBangEgg(7);
	};

	// 开启金蛋 银币
	ele.cd_open.onclick = () => {
		goldEggBangEgg(8);
	};
	// 开启金蛋 锤子
	ele.cd_cuizhi_open.onclick = () => {
		goldEggBangEgg(8);
	};
	// 开启金蛋 锤子
	ele.cd_cuizhi_open2.onclick = () => {
		goldEggBangEgg(8);
	};

	// 开启钻石蛋 银币
	ele.zsd_open.onclick = () => {
		goldEggBangEgg(9);
	};

	// 砸蛋
	function goldEggBangEgg(type) {
		let token = getCookie("token");
		ajax({
			url: API_PATH.GOLD_EGG_BANG_EGG,
			method: "POST",
			header: {
				Authorization: token,
			},
			data: {
				type: type,
			},
			success: (res) => {
				if (res.code == 1) {
					goldEggIndex();
					ele.tipsbtn.innerHTML = "领取";
					// console.log(res.data.info.b_type);
					if (res.data.info.b_type) {
						if (res.data.info.b_type == 1) {
							ele.recieveimg.src = "http://img.qxgs.cc/tiantianlaishouzu/img/home/yinbi3.png";
						} else if (res.data.info.b_type == 2) {
							ele.recieveimg.src = "http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi3.png";
						}
						ele.recieveimg.className = "flexcolomimg1";
						ele.recievenum.innerHTML =
							"<span>" + res.data.num + res.data.info.name + "</span>";
					} else {
						ele.recieveimg.src = IMG_DOMAIN + res.data.info.logo;
						let pj_type =
							res.data.info.hammer == 6 ?
							"itemred" :
							res.data.info.hammer == 2 ?
							"itemgreen" :
							res.data.info.hammer == 3 ?
							"itemblue" :
							res.data.info.hammer == 4 ?
							"itempurple" :
							res.data.info.hammer == 5 ?
							"itemorange" :
							"";
						ele.recievenum.innerHTML =
							"<span>" +
							res.data.info.name +
							"x" +
							parseInt(res.data.num) +
							"</span>";
						ele.recieveimg.className = "flexcolomimg1 " + pj_type;
					}
					if (res.data.info.is_default == 3) {
						let pj_type =
							res.data.info.hammer == 6 ?
							"itemred" :
							res.data.info.hammer == 2 ?
							"flexcolog1" :
							res.data.info.hammer == 3 ?
							"itemblue" :
							res.data.info.hammer == 4 ?
							"flexcolog2" :
							res.data.info.hammer == 5 ?
							"flexcolog3" :
							"";
						let mz_type =
							res.data.info.hammer == 6 ?
							"itemred" :
							res.data.info.hammer == 2 ?
							"mingzi1" :
							res.data.info.hammer == 3 ?
							"itemblue" :
							res.data.info.hammer == 4 ?
							"mingzi2" :
							res.data.info.hammer == 5 ?
							"mingzi3" :
							"";
						ele.floimg.style.display = "block";
						ele.recievenum.style.display = "none";
						ele.recieveimg.style.display = "none";
						ele.recieveimg2.className = pj_type;
						ele.recieveimg2.src = IMG_DOMAIN + res.data.info.rc_info.logo;
						ele.mingzi.innerHTML =
							"<p>" +
							res.data.info.rc_info.class.jz_name +
							'</p><span class="' +
							mz_type +
							'">' +
							res.data.info.rc_info.name +
							"</span>";
					} else {
						ele.floimg.style.display = "none";
						ele.recievenum.style.display = "block";
						ele.recieveimg.style.display = "block";
					}
					openMdl(ele.modal_tips2);
					// openTips(res.msg);
				} else openTips(res.msg || "未知错误");
			},
		});
	}

	function iosone() {
		window.webkit.messageHandlers.getuuid.postMessage("");
	}
	// window.callBackuuid = function(params) {
	// 	aidfa = params.idfa;
	// 	duoyou4(aidfa);
	// 	// params.idfa
	// }

	let map = "";
	ele.xianwan_open.onclick = () => {
		if (ptype == 2) {
			map = window.android.getOaid();
			map = JSON.parse(map);
			let sit = setInterval(() => {
				if (!map.sysver && !map.device && !map.oaid) return;
				else {
					clearInterval(sit);
					xwGame();
				}
			}, 100);
		} else if (ptype == 1) {
			// 苹果试玩
			// duoyou4(aidfa)
			iosone();
			window.callBackuuid = function(params) {
				aidfa = params.idfa;
				// alert(aidfa)
				duoyou4(params.idfa);
				// params.idfa
			};
		} else {
			openTips("请下载安卓最新版体验");
		}
	};

	// 天天来收租ios：
	// appid:11145
	// appSecret ：8oi0n54x77zyazv1
	// 服务端KEY：l6F5KiM822is36A9
	function duoyou4(aidfa) {
		let appid = "11145";
		let appsign = uid;
		let deviceid = aidfa;
		let ptype = 1;

		let str = appid + deviceid + ptype + appsign + "8oi0n54x77zyazv1";

		let sign2 = hex_md5(str);
		// alert(sign2)
		let src2 =
			"https://h5.17xianwan.com/try/iOS/try_list_ios?" +
			"ptype=" +
			ptype +
			"&deviceid=" +
			deviceid +
			"&appid=" +
			appid +
			"&appsign=" +
			appsign +
			"&keycode=" +
			sign2 +
			"&xwversion=" +
			2;
		// alert(src2, '闲玩  ios')
		setCookie("src4", src2);
		if (getCookie("src4")) {
			location.href = "renzheng4.html";
		}
	}

	// 闲玩
	// appid:11092
	// appSecret ：9lrtnsj3ck6icwdn
	// 服务端KEY：8mV9he0a9myf0707
	function xwGame() {
		let appid = "11092";
		let appsign = uid;
		let deviceid = window.android.getDeviceId();
		let msaoaid = "";
		let androidosv = window.android.getAndroidOsv();
		if (deviceid != null || deviceid != "") {
			deviceid = deviceid;
		} else {
			deviceid = 0;
		}
		if (androidosv != null || androidosv != "") {
			androidosv = androidosv;
		} else {
			androidosv = 29;
		}
		if (map.oaid == null || map.oaid == "") {
			msaoaid = "";
		} else {
			msaoaid = map.oaid;
		}
		let str =
			appid +
			deviceid +
			msaoaid +
			androidosv +
			ptype +
			appsign +
			"9lrtnsj3ck6icwdn";
		let sign2 = hex_md5(str);
		let src2 =
			"https://h5.17xianwan.com/try/try_list_plus?" +
			"appid=" +
			appid +
			"&msaoaid=" +
			msaoaid +
			"&androidosv=" +
			androidosv +
			"&deviceid=" +
			deviceid +
			"&ptype=" +
			ptype +
			"&appsign=" +
			appsign +
			"&keycode=" +
			sign2 +
			"&xwversion=" +
			2;
		location.href = src2;
	}
})();